當 python 線程在網絡調用(HTTPS)中並且發生上下文切換時會發生什麼? (What happens when the python thread is in network call(HTTPS) and the context switch happens?)


問題描述

當 python 線程在網絡調用(HTTPS)中並且發生上下文切換時會發生什麼? (What happens when the python thread is in network call(HTTPS) and the context switch happens?)

我遇到了一個問題,我們編寫的多線程下載應用程序有時會出現 408 錯誤。我們認為這可能是因為用戶增加了線程數,這導致了錯誤。我們認為有可能在網絡調用期間,發生上下文切換,導致線程沒有發送調用成功所需的所有數據包,並且服務器給出 408 超時錯誤。這是可能的還是網絡調用不依賴於上下文切換。

我們正在使用 python 線程和 pycurl 模塊使用 120 個線程下載數據。


參考解法

方法 1:

What context switch are you referring to?

Pycurl is a wrapper around libcurl which is a C library. When any of libcurl's methods are called, Python's global interpreter lock is released. Python runtime may run its own threads while libcurl is performing client‑side processing, or during actual network I/O, but "context switches" aren't attached to network I/O in any way.

This shouldn't affect your troubleshooting however because you should be using a packet capture tool like tcpdump to record your traffic and identify which side is sending what when you are getting the errors so that you can make some reasoned theories as to what might be going on instead of guessing.

(by AmritD. SM)

參考文件

  1. What happens when the python thread is in network call(HTTPS) and the context switch happens? (CC BY‑SA 2.5/3.0/4.0)

#pycurl #Python #multithreading






相關問題

python中的握手失敗(_ssl.c:590) (HandShake Failure in python(_ssl.c:590))

SmugMug 的變化似乎炸毀了 pysmug (changes at SmugMug appear to have blown up pysmug)

pycurl/curl 不遵循 CURLOPT_TIMEOUT 選項 (pycurl/curl not following the CURLOPT_TIMEOUT option)

需要幫助從 curl 遷移到 pycurl (need help with moving from curl to pycurl)

Tornado 的 AsyncHTTPClient 從 1.2 升級到 2.0 後不再工作 (Tornado's AsyncHTTPClient no longer works after upgrade to 2.0 from 1.2)

PyCurl 替代方案,libcurl 的 pythonic 包裝器? (PyCurl alternative, a pythonic wrapper for libcurl?)

使用 Pycurl 獲取 HTML (Getting HTML with Pycurl)

如果請求的數據有時被壓縮,有時不被壓縮,如何使用 pycurl? (how to use pycurl if requested data is sometimes gzipped, sometimes not?)

在 MacOS 上安裝 pycurl。(鏈接時 ssl 後端(無/其他)與編譯時 ssl 後端(openssl)不同) (Installing pycurl on MacOS. (link-time ssl backend (none/other) is different from compile-time ssl backend (openssl)))

Python 3.7:在 Windows 10 上安裝 pycurl (Python 3.7: pycurl installation on Windows 10)

Windows 機器在 Thonny 上安裝 pycurl 模塊 (Windows machine Installing pycurl module on Thonny)

當 python 線程在網絡調用(HTTPS)中並且發生上下文切換時會發生什麼? (What happens when the python thread is in network call(HTTPS) and the context switch happens?)







留言討論